<template>
  <div id="addPictureBatchPage">
    <h2 style="margin-bottom: 16px">批量创建图片</h2>
    <!--图片信息表单-->
    <a-form name="formData" layout="vertical" :model="formData" @finish="headleSubmit">
      <a-form-item name="searchText" label="关键词">
        <a-input v-model:value="formData.searchText" placeholder="请输入关键词" allow-clear />
      </a-form-item>
      <a-form-item name="count" label="抓取图片数量(一次不能超过30张)">
        <a-input-number
          v-model:value="formData.count"
          placeholder="请输入抓取数量"
          style="min-width: 200px; min-height: 30px"
          :min="1"
          :max="30"
        />
      </a-form-item>
      <a-form-item name="namePrefix" label="名称前缀">
        <a-input
          v-model:value="formData.namePrefix"
          placeholder="请输入图片名称前缀，会自动补充序号"
          allow-clear
        />
      </a-form-item>
      <a-form-item>
        <a-button type="primary" html-type="submit" style="width: 100%" :loading="loading">
          开始创建
        </a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import PictureUpload from '@/components/PictureUpload.vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import {
  editPictureUsingPost,
  getPictureByIdUsingGet,
  uploadPictureByBatchUsingPost,
} from '@/api/pictureController.ts'
import { useRoute, useRouter } from 'vue-router'
import _default from 'ant-design-vue/es/vc-slick/inner-slider'
import data = _default.data
import router from '@/router'

const formData = reactive<API.PictureUploadByBatchRequest>({
  count: 10,
})
const route = useRoute()
const loading = ref(false)

/**
 * 表单提交事件
 * @param values
 */
const headleSubmit = async (values: any) => {
  loading.value = true

  const res = await uploadPictureByBatchUsingPost({
    ...formData,
  })
  // 操作成功
  if (res.data.code === 0 && res.data.data) {
    message.success(`创建成功,共${res.data.data}张图片`)

    //跳转到图片详情页
    router.push({
      path: `/`,
    })
  } else {
    message.error('创建失败' + res.data.message)
  }
  loading.value = false
}


</script>
<style scoped>
#addPictureBatchPage {
  max-width: 720px;
  margin: 0 auto;
}
</style>
